#include <iostream>
#include <dlfcn.h>
#include <string>
#include <sstream>

using namespace std ;

const int MAX_STRING_SIZE= 80 ;

void invoke_method ( const char * lib, const char * method, float argument )
{
	void * dl_handle ;
	typedef float (*pFunc) (float) ;
	pFunc func ;
	char * error ;

	//open the library
	dl_handle = dlopen ( lib, RTLD_LAZY ) ;
	if ( !dl_handle )
	{
		cout<< "!!! " << dlerror() << endl ;
		return ;
	}

	//resolve the symbol(method) from the library
	func = (pFunc) dlsym ( dl_handle, method ) ;
	error = dlerror () ;
	if (error)
	{
		cout<< "!!! " << error << endl ;
		return ;
	}

	//Run the method
	cout<< (*func)(argument) << endl ;
	
	//close the library
	dlclose ( dl_handle ) ;

}

int main ( int argc, char ** argv )
{
	string input ;
	string lib, method ;
	float argument ;

	while ( true )
	{
		cout<< "> " ;
		getline ( cin, input ) ;

		istringstream iss ( input ) ;
		iss >> lib ;

		if ( lib == "bye" )
			break ;
		
		iss >> method >> argument ;

		invoke_method ( lib.c_str(), method.c_str(), argument ) ;
	}

	return 0 ;
}
		
		
	
